using System;
using System.Web;
using System.Web.Http;
using Yz.Base.Dal;
using Yz.Model.Dal;

namespace Yz.ApiService
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

        }
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpContext.Current.Items[DBContextName.YzContext] = new YzContext();
        }
        protected void Application_EndRequest()
        {
            var dbContext = HttpContext.Current.Items[DBContextName.YzContext] as YzContext;
            if (dbContext != null)
                dbContext.Dispose();

        }
    }
}
